Passed
Push — master ( 2a1989...241100 )
by Stream
08:02 queued 36s
created

script.js ➔ resize   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
dl 0
loc 4
rs 10
1
var lfm_route = location.origin + location.pathname;
2
var show_list;
3
var sort_type = 'alphabetic';
4
var multi_selection_enabled = false;
5
var selected = [];
6
var items = [];
7
8
$.fn.fab = function (options) {
9
  var menu = this;
10
  menu.addClass('fab-wrapper');
11
12
  var toggler = $('<a>')
13
    .addClass('fab-button fab-toggle')
14
    .append($('<i>').addClass('fas fa-plus'))
15
    .click(function () {
16
      menu.toggleClass('fab-expand');
17
    });
18
19
  menu.append(toggler);
20
21
  options.buttons.forEach(function (button) {
22
    toggler.before(
23
      $('<a>').addClass('fab-button fab-action')
24
        .attr('data-label', button.label)
25
        .attr('id', button.attrs.id)
26
        .append($('<i>').addClass(button.icon))
27
        .click(function () {
28
          menu.removeClass('fab-expand');
29
        })
30
    );
31
  });
32
};
33
34
$(document).ready(function () {
35
  $('#fab').fab({
36
    buttons: [
37
      {
38
        icon: 'fas fa-upload',
39
        label: lang['nav-upload'],
0 ignored issues
show
Bug introduced by
The variable lang seems to be never declared. If this is a global, consider adding a /** global: lang */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
40
        attrs: {id: 'upload'}
41
      },
42
      {
43
        icon: 'fas fa-folder',
44
        label: lang['nav-new'],
45
        attrs: {id: 'add-folder'}
46
      }
47
    ]
48
  });
49
50
  actions.reverse().forEach(function (action) {
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
51
    $('#nav-buttons > ul').prepend(
52
      $('<li>').addClass('nav-item').append(
53
        $('<a>').addClass('nav-link d-none')
54
          .attr('data-action', action.name)
55
          .attr('data-multiple', action.multiple)
56
          .append($('<i>').addClass('fas fa-fw fa-' + action.icon))
57
          .append($('<span>').text(action.label))
58
      )
59
    );
60
  });
61
62
  sortings.forEach(function (sort) {
0 ignored issues
show
Bug introduced by
The variable sortings seems to be never declared. If this is a global, consider adding a /** global: sortings */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
63
    $('#nav-buttons .dropdown-menu').append(
64
      $('<a>').addClass('dropdown-item').attr('data-sortby', sort.by)
65
        .append($('<i>').addClass('fas fa-fw fa-' + sort.icon))
66
        .append($('<span>').text(sort.label))
67
        .click(function() {
68
          sort_type = sort.by;
69
          loadItems();
70
        })
71
    );
72
  });
73
74
  loadFolders();
75
  performLfmRequest('errors')
76
    .done(function (response) {
77
      JSON.parse(response).forEach(function (message) {
78
        $('#alerts').append(
79
          $('<div>').addClass('alert alert-warning')
80
            .append($('<i>').addClass('fas fa-exclamation-circle'))
81
            .append(' ' + message)
82
        );
83
      });
84
    });
85
86
  $(window).on('dragenter', function(){
87
    $('#uploadModal').modal('show');
88
  });
89
90
  if (usingWysiwygEditor()) {
91
    $('#multi_selection_toggle').hide();
92
  }
93
});
94
95
// ======================
96
// ==  Navbar actions  ==
97
// ======================
98
99
$('#multi_selection_toggle').click(function () {
100
  multi_selection_enabled = !multi_selection_enabled;
101
102
  $('#multi_selection_toggle i')
103
    .toggleClass('fa-times', multi_selection_enabled)
104
    .toggleClass('fa-check-double', !multi_selection_enabled);
105
106
  if (!multi_selection_enabled) {
107
    clearSelected();
108
  }
109
});
110
111
$('#to-previous').click(function () {
112
  var previous_dir = getPreviousDir();
113
  if (previous_dir == '') return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
114
  goTo(previous_dir);
115
});
116
117
function toggleMobileTree(should_display) {
118
  if (should_display === undefined) {
119
    should_display = !$('#tree').hasClass('in');
120
  }
121
  $('#tree').toggleClass('in', should_display);
122
}
123
124
$('#show_tree').click(function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
125
  toggleMobileTree();
126
});
127
128
$('#main').click(function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
129
  if ($('#tree').hasClass('in')) {
130
    toggleMobileTree(false);
131
  }
132
});
133
134
$(document).on('click', '#add-folder', function () {
135
  dialog(lang['message-name'], '', createFolder);
0 ignored issues
show
Bug introduced by
The variable lang seems to be never declared. If this is a global, consider adding a /** global: lang */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
136
});
137
138
$(document).on('click', '#upload', function () {
139
  $('#uploadModal').modal('show');
140
});
141
142
$(document).on('click', '[data-display]', function() {
143
  show_list = $(this).data('display');
144
  loadItems();
145
});
146
147
$(document).on('click', '[data-action]', function() {
148
  window[$(this).data('action')]($(this).data('multiple') ? getSelectedItems() : getOneSelectedElement());
149
});
150
151
// ==========================
152
// ==  Multiple Selection  ==
153
// ==========================
154
155
function toggleSelected (e) {
156
  if (!multi_selection_enabled) {
157
    selected = [];
158
  }
159
160
  var sequence = $(e.target).closest('a').data('id');
161
  var element_index = selected.indexOf(sequence);
162
  if (element_index === -1) {
163
    selected.push(sequence);
164
  } else {
165
    selected.splice(element_index, 1);
166
  }
167
168
  updateSelectedStyle();
169
}
170
171
function clearSelected () {
172
  selected = [];
173
174
  multi_selection_enabled = false;
175
176
  updateSelectedStyle();
177
}
178
179
function updateSelectedStyle() {
180
  items.forEach(function (item, index) {
181
    $('[data-id=' + index + ']')
182
      .find('.square')
183
      .toggleClass('selected', selected.indexOf(index) > -1);
184
  });
185
  toggleActions();
186
}
187
188
function getOneSelectedElement(orderOfItem) {
189
  var index = orderOfItem !== undefined ? orderOfItem : selected[0];
190
  return items[index];
191
}
192
193
function getSelectedItems() {
194
  return selected.reduce(function (arr_objects, id) {
195
    arr_objects.push(getOneSelectedElement(id));
196
    return arr_objects
197
  }, []);
198
}
199
200
function toggleActions() {
201
  var one_selected = selected.length === 1;
202
  var many_selected = selected.length >= 1;
203
  var only_image = getSelectedItems()
204
    .filter(function (item) { return !item.is_image; })
205
    .length === 0;
206
  var only_file = getSelectedItems()
207
    .filter(function (item) { return !item.is_file; })
208
    .length === 0;
209
210
  $('[data-action=use]').toggleClass('d-none', !(many_selected && only_file));
211
  $('[data-action=rename]').toggleClass('d-none', !one_selected);
212
  $('[data-action=preview]').toggleClass('d-none', !(many_selected && only_file));
213
  $('[data-action=move]').toggleClass('d-none', !many_selected);
214
  $('[data-action=download]').toggleClass('d-none', !(many_selected && only_file));
215
  $('[data-action=resize]').toggleClass('d-none', !(one_selected && only_image));
216
  $('[data-action=crop]').toggleClass('d-none', !(one_selected && only_image));
217
  $('[data-action=trash]').toggleClass('d-none', !many_selected);
218
  $('[data-action=open]').toggleClass('d-none', !one_selected || only_file);
219
  $('#multi_selection_toggle').toggleClass('d-none', usingWysiwygEditor() || !many_selected);
220
  $('#actions').toggleClass('d-none', selected.length === 0);
221
  $('#fab').toggleClass('d-none', selected.length !== 0);
222
}
223
224
// ======================
225
// ==  Folder actions  ==
226
// ======================
227
228
$(document).on('click', '#tree a', function (e) {
229
  goTo($(e.target).closest('a').data('path'));
230
  toggleMobileTree(false);
231
});
232
233
function goTo(new_dir) {
234
  $('#working_dir').val(new_dir);
235
  loadItems();
236
}
237
238
function getPreviousDir() {
239
  var working_dir = $('#working_dir').val();
240
  return working_dir.substring(0, working_dir.lastIndexOf('/'));
241
}
242
243
function setOpenFolders() {
244
  $('#tree [data-path]').each(function (index, folder) {
245
    // close folders that are not parent
246
    var should_open = ($('#working_dir').val() + '/').startsWith($(folder).data('path') + '/');
247
    $(folder).children('i')
248
      .toggleClass('fa-folder-open', should_open)
249
      .toggleClass('fa-folder', !should_open);
250
  });
251
252
  $('#tree .nav-item').removeClass('active');
253
  $('#tree [data-path="' + $('#working_dir').val() + '"]').parent('.nav-item').addClass('active');
254
}
255
256
// ====================
257
// ==  Ajax actions  ==
258
// ====================
259
260
function performLfmRequest(url, parameter, type) {
261
  var data = defaultParameters();
262
263
  if (parameter != null) {
0 ignored issues
show
Best Practice introduced by
Comparing parameter to null using the != operator is not safe. Consider using !== instead.
Loading history...
264
    $.each(parameter, function (key, value) {
265
      data[key] = value;
266
    });
267
  }
268
269
  return $.ajax({
270
    type: 'GET',
271
    beforeSend: function(request) {
272
      var token = getUrlParam('token');
273
      if (token !== null) {
274
        request.setRequestHeader("Authorization", 'Bearer ' + token);
275
      }
276
    },
277
    dataType: type || 'text',
278
    url: lfm_route + '/' + url,
279
    data: data,
280
    cache: false
281
  }).fail(function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
282
    displayErrorResponse(jqXHR);
283
  });
284
}
285
286
function displayErrorResponse(jqXHR) {
287
  notify('<div style="max-height:50vh;overflow: scroll;">' + jqXHR.responseText + '</div>');
288
}
289
290
var refreshFoldersAndItems = function (data) {
291
  loadFolders();
292
  if (data != 'OK') {
293
    data = Array.isArray(data) ? data.join('<br/>') : data;
294
    notify(data);
295
  }
296
};
297
298
var hideNavAndShowEditor = function (data) {
299
  $('#nav-buttons > ul').addClass('d-none');
300
  $('#content').html(data).removeClass('preserve_actions_space');
301
  clearSelected();
302
}
303
304
function loadFolders() {
305
  performLfmRequest('folders', {}, 'html')
306
    .done(function (data) {
307
      $('#tree').html(data);
308
      loadItems();
309
    });
310
}
311
312
function loadItems() {
313
  loading(true);
314
  performLfmRequest('jsonitems', {show_list: show_list, sort_type: sort_type}, 'html')
315
    .done(function (data) {
316
      selected = [];
317
      var response = JSON.parse(data);
318
      var working_dir = response.working_dir;
319
      items = response.items;
320
      var hasItems = items.length !== 0;
321
      $('#empty').toggleClass('d-none', hasItems);
322
      $('#content').html('').removeAttr('class');
323
324
      if (hasItems) {
325
        $('#content').addClass(response.display).addClass('preserve_actions_space');
326
327
        items.forEach(function (item, index) {
328
          var template = $('#item-template').clone()
329
            .removeAttr('id class')
330
            .attr('data-id', index)
331
            .click(toggleSelected)
332
            .dblclick(function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
333
              if (item.is_file) {
334
                use(getSelectedItems());
335
              } else {
336
                goTo(item.url);
337
              }
338
            });
339
340
          if (item.thumb_url) {
341
            var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '?timestamp=' + item.time + '")');
342
          } else {
343
            var icon = $('<div>').addClass('ico');
344
            var image = $('<div>').addClass('mime-icon ico-' + item.icon).append(icon);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable image already seems to be declared on line 341. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
345
          }
346
347
          template.find('.square').append(image);
348
          template.find('.item_name').text(item.name);
349
          template.find('time').text((new Date(item.time * 1000)).toLocaleString());
350
351
          $('#content').append(template);
352
        });
353
      }
354
355
      $('#nav-buttons > ul').removeClass('d-none');
356
357
      $('#working_dir').val(working_dir);
358
      console.log('Current working_dir : ' + working_dir);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
359
      var breadcrumbs = [];
360
      var validSegments = working_dir.split('/').filter(function (e) { return e; });
361
      validSegments.forEach(function (segment, index) {
362
        if (index === 0) {
363
          // set root folder name as the first breadcrumb
364
          breadcrumbs.push($("[data-path='/" + segment + "']").text());
365
        } else {
366
          breadcrumbs.push(segment);
367
        }
368
      });
369
370
      $('#current_folder').text(breadcrumbs[breadcrumbs.length - 1]);
371
      $('#breadcrumbs > ol').html('');
372
      breadcrumbs.forEach(function (breadcrumb, index) {
373
        var li = $('<li>').addClass('breadcrumb-item').text(breadcrumb);
374
375
        if (index === breadcrumbs.length - 1) {
376
          li.addClass('active').attr('aria-current', 'page');
377
        } else {
378
          li.click(function () {
379
            // go to corresponding path
380
            goTo('/' + validSegments.slice(0, 1 + index).join('/'));
381
          });
382
        }
383
384
        $('#breadcrumbs > ol').append(li);
385
      });
386
387
      var atRootFolder = getPreviousDir() == '';
388
      $('#to-previous').toggleClass('d-none invisible-lg', atRootFolder);
389
      $('#show_tree').toggleClass('d-none', !atRootFolder).toggleClass('d-block', atRootFolder);
390
      setOpenFolders();
391
      loading(false);
392
      toggleActions();
393
    });
394
}
395
396
function loading(show_loading) {
397
  $('#loading').toggleClass('d-none', !show_loading);
398
}
399
400
function createFolder(folder_name) {
401
  performLfmRequest('newfolder', {name: folder_name})
402
    .done(refreshFoldersAndItems);
403
}
404
405
// ==================================
406
// ==         File Actions         ==
407
// ==================================
408
409
function rename(item) {
410
  dialog(lang['message-rename'], item.name, function (new_name) {
0 ignored issues
show
Bug introduced by
The variable lang seems to be never declared. If this is a global, consider adding a /** global: lang */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
411
    performLfmRequest('rename', {
412
      file: item.name,
413
      new_name: new_name
414
    }).done(refreshFoldersAndItems);
415
  });
416
}
417
418
function trash(items) {
419
  notify(lang['message-delete'], function () {
0 ignored issues
show
Bug introduced by
The variable lang seems to be never declared. If this is a global, consider adding a /** global: lang */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
420
    performLfmRequest('delete', {
421
      items: items.map(function (item) { return item.name; })
422
    }).done(refreshFoldersAndItems)
423
  });
424
}
425
426
function crop(item) {
427
  performLfmRequest('crop', {img: item.name})
428
    .done(hideNavAndShowEditor);
429
}
430
431
function resize(item) {
432
  performLfmRequest('resize', {img: item.name})
433
    .done(hideNavAndShowEditor);
434
}
435
436
function download(items) {
437
  items.forEach(function (item, index) {
438
    var data = defaultParameters();
439
440
    data['file'] = item.name;
441
442
    var token = getUrlParam('token');
443
    if (token) {
444
      data['token'] = token;
445
    }
446
447
    setTimeout(function () {
448
      location.href = lfm_route + '/download?' + $.param(data);
449
    }, index * 100);
450
  });
451
}
452
453
function open(item) {
454
  goTo(item.url);
455
}
456
457
function preview(items) {
458
  var carousel = $('#carouselTemplate').clone().attr('id', 'previewCarousel').removeClass('d-none');
459
  var imageTemplate = carousel.find('.carousel-item').clone().removeClass('active');
460
  var indicatorTemplate = carousel.find('.carousel-indicators > li').clone().removeClass('active');
461
  carousel.children('.carousel-inner').html('');
462
  carousel.children('.carousel-indicators').html('');
463
  carousel.children('.carousel-indicators,.carousel-control-prev,.carousel-control-next').toggle(items.length > 1);
464
465
  items.forEach(function (item, index) {
466
    var carouselItem = imageTemplate.clone()
467
      .addClass(index === 0 ? 'active' : '');
468
469
    if (item.thumb_url) {
470
      carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '?timestamp=' + item.time + '\')');
471
    } else {
472
      carouselItem.find('.carousel-image').css('width', '50vh').append($('<div>').addClass('mime-icon ico-' + item.icon));
473
    }
474
475
    carouselItem.find('.carousel-label').attr('target', '_blank').attr('href', item.url)
476
      .append(item.name)
477
      .append($('<i class="fas fa-external-link-alt ml-2"></i>'));
478
479
    carousel.children('.carousel-inner').append(carouselItem);
480
481
    var carouselIndicator = indicatorTemplate.clone()
482
      .addClass(index === 0 ? 'active' : '')
483
      .attr('data-slide-to', index);
484
    carousel.children('.carousel-indicators').append(carouselIndicator);
485
  });
486
487
488
  // carousel swipe control
489
  var touchStartX = null;
490
491
  carousel.on('touchstart', function (event) {
492
    var e = event.originalEvent;
493
    if (e.touches.length == 1) {
0 ignored issues
show
Best Practice introduced by
Comparing e.touches.length to 1 using the == operator is not safe. Consider using === instead.
Loading history...
494
      var touch = e.touches[0];
495
      touchStartX = touch.pageX;
496
    }
497
  }).on('touchmove', function (event) {
498
    var e = event.originalEvent;
499
    if (touchStartX != null) {
0 ignored issues
show
Best Practice introduced by
Comparing touchStartX to null using the != operator is not safe. Consider using !== instead.
Loading history...
500
      var touchCurrentX = e.changedTouches[0].pageX;
501
      if ((touchCurrentX - touchStartX) > 60) {
502
        touchStartX = null;
503
        carousel.carousel('prev');
504
      } else if ((touchStartX - touchCurrentX) > 60) {
505
        touchStartX = null;
506
        carousel.carousel('next');
507
      }
508
    }
509
  }).on('touchend', function () {
510
    touchStartX = null;
511
  });
512
  // end carousel swipe control
513
514
  notify(carousel);
515
}
516
517
function move(items) {
518
  performLfmRequest('move', { items: items.map(function (item) { return item.name; }) })
519
    .done(refreshFoldersAndItems);
520
}
521
522
function getUrlParam(paramName) {
523
  var reParam = new RegExp('(?:[\?&]|&)' + paramName + '=([^&]+)', 'i');
524
  var match = window.location.search.match(reParam);
525
  return ( match && match.length > 1 ) ? match[1] : null;
526
}
527
528
function use(items) {
529
  function useTinymce3(url) {
530
    if (!usingTinymce3()) { return; }
531
532
    var win = tinyMCEPopup.getWindowArg("window");
0 ignored issues
show
Bug introduced by
The variable tinyMCEPopup seems to be never declared. If this is a global, consider adding a /** global: tinyMCEPopup */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
533
    win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url;
534
    if (typeof(win.ImageDialog) != "undefined") {
535
      // Update image dimensions
536
      if (win.ImageDialog.getImageData) {
537
        win.ImageDialog.getImageData();
538
      }
539
540
      // Preview if necessary
541
      if (win.ImageDialog.showPreviewImage) {
542
        win.ImageDialog.showPreviewImage(url);
543
      }
544
    }
545
    tinyMCEPopup.close();
546
  }
547
548
  function useTinymce4AndColorbox(url) {
549
    if (!usingTinymce4AndColorbox()) { return; }
550
551
    parent.document.getElementById(getUrlParam('field_name')).value = url;
0 ignored issues
show
Bug introduced by
The variable parent seems to be never declared. If this is a global, consider adding a /** global: parent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
552
553
    if(typeof parent.tinyMCE !== "undefined") {
554
      parent.tinyMCE.activeEditor.windowManager.close();
555
    }
556
    if(typeof parent.$.fn.colorbox !== "undefined") {
557
      parent.$.fn.colorbox.close();
558
    }
559
  }
560
561
  function useTinymce5(url){
562
    if (!usingTinymce5()) { return; }
563
564
    parent.postMessage({
0 ignored issues
show
Bug introduced by
The variable parent seems to be never declared. If this is a global, consider adding a /** global: parent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
565
      mceAction: 'insert',
566
      content: url
567
    });
568
569
    parent.postMessage({ mceAction: 'close' });
570
  }
571
572
  function useCkeditor3(url) {
573
    if (!usingCkeditor3()) { return; }
574
575
    if (window.opener) {
576
      // Popup
577
      window.opener.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url);
578
    } else {
579
      // Modal (in iframe)
580
      parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url);
0 ignored issues
show
Bug introduced by
The variable parent seems to be never declared. If this is a global, consider adding a /** global: parent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
581
      parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorCleanUpFuncNum'));
582
    }
583
  }
584
585
  function useFckeditor2(url) {
586
    if (!usingFckeditor2()) { return; }
587
588
    var p = url;
589
    var w = data['Properties']['Width'];
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. If this is a global, consider adding a /** global: data */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
590
    var h = data['Properties']['Height'];
591
    window.opener.SetUrl(p,w,h);
592
  }
593
594
  var url = items[0].url;
595
  var callback = getUrlParam('callback');
596
  var useFileSucceeded = true;
597
598
  if (usingWysiwygEditor()) {
599
    useTinymce3(url);
600
601
    useTinymce4AndColorbox(url);
602
603
    useTinymce5(url);
604
605
    useCkeditor3(url);
606
607
    useFckeditor2(url);
608
  } else if (callback && window[callback]) {
609
    window[callback](getSelectedItems());
610
  } else if (callback && parent[callback]) {
0 ignored issues
show
Bug introduced by
The variable parent seems to be never declared. If this is a global, consider adding a /** global: parent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
611
    parent[callback](getSelecteditems());
612
  } else if (window.opener) { // standalone button or other situations
613
    window.opener.SetUrl(getSelectedItems());
614
  } else {
615
    useFileSucceeded = false;
616
  }
617
618
  if (useFileSucceeded) {
619
    if (window.opener) {
620
      window.close();
621
    }
622
  } else {
623
    console.log('window.opener not found');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
624
    // No editor found, open/download file using browser's default method
625
    window.open(url);
626
  }
627
}
628
//end useFile
629
630
// ==================================
631
// ==     WYSIWYG Editors Check    ==
632
// ==================================
633
634
function usingTinymce3() {
635
  return !!window.tinyMCEPopup;
636
}
637
638
function usingTinymce4AndColorbox() {
639
  return !!getUrlParam('field_name');
640
}
641
642
function usingTinymce5(){
643
    return !!getUrlParam('editor');
644
}
645
646
function usingCkeditor3() {
647
  return !!getUrlParam('CKEditor') || !!getUrlParam('CKEditorCleanUpFuncNum');
648
}
649
650
function usingFckeditor2() {
651
  return window.opener && typeof data != 'undefined' && data['Properties']['Width'] != '';
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. If this is a global, consider adding a /** global: data */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
652
}
653
654
function usingWysiwygEditor() {
655
  return usingTinymce3() || usingTinymce4AndColorbox() || usingTinymce5() || usingCkeditor3() || usingFckeditor2();
656
}
657
658
// ==================================
659
// ==            Others            ==
660
// ==================================
661
662
function defaultParameters() {
663
  return {
664
    working_dir: $('#working_dir').val(),
665
    type: $('#type').val()
666
  };
667
}
668
669
function notImp() {
670
  notify('Not yet implemented!');
671
}
672
673
function notify(body, callback) {
674
  $('#notify').find('.btn-primary').toggle(callback !== undefined);
675
  $('#notify').find('.btn-primary').unbind().click(callback);
676
  $('#notify').modal('show').find('.modal-body').html(body);
677
}
678
679
function dialog(title, value, callback) {
680
  $('#dialog').find('input').val(value);
681
  $('#dialog').on('shown.bs.modal', function () {
682
    $('#dialog').find('input').focus();
683
  });
684
  $('#dialog').find('.btn-primary').unbind().click(function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
685
    callback($('#dialog').find('input').val());
686
  });
687
  $('#dialog').modal('show').find('.modal-title').text(title);
688
}
689